package org.example.petitionplatformsystem.controller;

import org.example.petitionplatformsystem.Response;
import org.example.petitionplatformsystem.converter.MailBoxConverter;
import org.example.petitionplatformsystem.dao.model.LeaderMailbox;
import org.example.petitionplatformsystem.dto.mailBoxDTO.MailBoxPostDTO;
import org.example.petitionplatformsystem.service.LeaderMailboxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/consulting")
public class leaderMailBoxController {
    //领导信箱表的服务
    private final LeaderMailboxService leaderMailboxService;
    @Autowired
    public leaderMailBoxController(LeaderMailboxService leaderMailboxService){
        this.leaderMailboxService = leaderMailboxService;
    }
    @PostMapping("/writeLetter")
    public Response<LeaderMailbox> writeLetter(@RequestBody MailBoxPostDTO mailBoxPostDTO){
        LeaderMailbox leaderMailbox = MailBoxConverter.convertToLeaderMailBox(mailBoxPostDTO);
        return Response.newSuccessResponse(leaderMailboxService.addLeaderMailbox(leaderMailbox));
    }
    @GetMapping("/getleaderMails/{userId}")
    public Response<List<LeaderMailbox>> getLeaderMails(@PathVariable long userId){

        return Response.newSuccessResponse(leaderMailboxService.getAllLeaderMailboxesByUserId(userId));
    }
    @GetMapping("getleaderMail/{mailboxId}")
    public Response<LeaderMailbox> getLeaderMail(@PathVariable long mailboxId){
        return Response.newSuccessResponse(leaderMailboxService.getLeaderMailboxById(mailboxId));
    }

}
